home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16184 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.1 KB

  1. Path: news.cais.com!news
  2. From: Eric Vought <adfh@ids2.idsonline.com>
  3. Newsgroups: comp.object,comp.lang.eiffel,comp.lang.c++,comp.lang.beta,comp.lang.java,comp.lang.sather
  4. Subject: Re: What Should An Exception Handling Do? -- Clarification of rules
  5. Date: Tue, 09 Apr 1996 17:31:49 -0400
  6. Organization: Capital Area Internet Service info@cais.com 703-448-4470
  7. Message-ID: <316AD745.68DE37AD@ids2.idsonline.com>
  8. References: <31647113.13BD8C66@cygnus.com> <4ke1kp$pem@newsbf02.news.aol.com>
  9. NNTP-Posting-Host: ip226.idsonline.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.01 (X11; I; Linux 1.2.13 i586)
  14.  
  15. > Real world case in point. Imagine a fictious object runtime which must
  16. > have one binary support the range of operating systems with the interface
  17. > identified as Win32. Under Win32s many file operations will return an
  18. > error code 87 when in fact Windows95 or Window NT will give a notification
  19. > code with more meaning. on the Win32s platform an error code 87 may
  20. > indicate a dire consequence or merely be an informative notification.
  21. > Structuring the File System framework to use exception handlers can allow
  22. > an 87 error code to raise an exception and let the arbitrator determine
  23. > the settlement of the outcome. That is to say, is this a trivial
  24. > notification? Or, is this a serious error condition. In the first case, we
  25. > may resume. In the second, we must take direct alternative action.
  26.  
  27. This is a perfect example of what I see as a bad use of exceptions. When
  28. the filesystem code recieves an error code 87, it should *not* throw an
  29. exception. Instead, it should try to determine the nature of the error
  30. *within* the method and then throw a more appropriate exception in a
  31. serious case. The problem is that throwing and processing an error in
  32. order to determine that, in fact, the situation is not dire takes just
  33. as long as processing a real error. Since, presumably, non-dire errors
  34. occur more often than dire errors, you are wasting a significant amount
  35. of processing power to throw and catch these exceptions. Additionally,
  36. you are violating encapsulation by allowing the error handling routine
  37. to affect the execution path of the method. This means that the caller
  38. must *know* how to affect the method's internal state, and therefore
  39. must know implementation details of the method. BAD.
  40.  
  41. The better way to do it is to have the public method call private
  42. methods which will terminate on errors (either by returning a signal
  43. value or throwing an exception). The public code then decides whether
  44. the condition is an error and either retries or resumes operation by
  45. calling further private methods or throws an exception from there.
  46.  
  47. Remember that the primary reason for exceptions is to support OOP and
  48. data encapsulation. In other words, for informing a client that
  49. something has occurred and allowing them to deal with it *without*
  50. revealing internal details. Within implementation code (which seems to
  51. be what resumption most directly supports), where one knows how the
  52. condition will be handled, return values and branch statements are more
  53. efficient, often simpler, and more elegant.
  54.  
  55.